<!DOCTYPE html>
<html style="height: 100%">
<head>
    <title>文档首页</title>
    <% include ../../layouts/import.ejs %>
</head>
<body style="height: 100%">
<% include ../../layouts/header.ejs %>
<div class="index container" style="background: white;">
    <div style="margin-top:20px">
        <input type="hidden" value="<%= id %>" id="id" name="id"/>
        <input type="hidden" value="<%= typeId %>" id="typeId" name="typeId"/>
        <input type="text" id="wordTitle" name="wordTitle"
               class="form-control" style="width: 100%;" placeholder="文档标题" value="<%= wordTitle %>"/>
        </div>
        <div id="editormd" style="top: 15px; z-index: 1;">
            <textarea style="display:none;" id="markdownStr" name="markdownStr"><%= wordContent %></textarea>
        </div>
    <div style="margin-top: 20px;">
        <button class="btn btn-success" id="save">保存</button>
    </div>
</div>
<script>
    $(document).ready(function () {
        var testEditor = editormd("editormd", {
            height: "600",
            path: "/lib/editor-md-master/lib/",
            saveHTMLToTextarea: true
        });

        $("#save").click(function () {
            var id = $('#id').val();
            var wordTitle = $('#wordTitle').val();
            var markdownStr = $('#markdownStr').val();
            var wordAuthor = $('#wordAuthor').val();
            var wordTime = $('#wordTime').val();
            var wordHtml = testEditor.getHTML();
            var typeId = $('#typeId').val();

            $.post('/daily/word/save', {
                id: id,
                wordContent: markdownStr,
                wordAuthor: wordAuthor,
                wordTime: wordTime,
                wordTitle: wordTitle,
                wordHtml: wordHtml,
                typeId:typeId
            }, function (result) {
                if (result.errcode === 0) {
                    location.href = '/daily/word/list'
                } else {
                    console.error(result.message);
                }
            });

        })

    });


</script>
</body>
</html>